<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
use app\admin\model\Job;

class Spread extends Rbac
{
//    推广部页面
    public function spread()
    {
        $info = Job::where('')->select();
        $count = count($info);
        $info = Job::where('')
            ->order('job_createtime','desc')
            ->paginate(6,$count);
//        var_dump($info);exit;
//            ->column('job_id,job_name,job_sex,job_phone,job_education,job_major,job_email,job_createtime,job_year');
//       对象转为数组
//        $data = [];
//        foreach ($info as $k=>$v){
//            $data[] = $v->toArray();
//        }
        $this->assign('info',$info);
        return $this->fetch('spread/user');
    }
//    推广部添加
    public function add(Request $req){
        if($req->post()){
            $data = input('post.');
            $data['job_createtime'] = time();
//            var_dump($data);exit;
            $res = Job::insert($data);
            if($res>0){
                $this->success('添加成功！','admin/spread/spread');
            }else{
                $this->error('添加失败！','admin/spread/spread');
            }
        }

        return $this->fetch('spread/useradd');
    }
//推广部删除
    public function del(Request $req){
        $job_id = $req->param('job_id');
        $res = Job::destroy($job_id);
        if($res>0){
            return 200;
        }else{
            return 100;
        }
    }
    //    查看详情页面
    public function test(){
        $job_id = request()->param('job_id');
        $result = Job::get($job_id)->toArray();
        $this->assign('result',$result);
        return $this->fetch('spread/test');
    }



}
